<?php


namespace apps\marriage\core\service;


use apps\marriage\core\model\PlatformAccount;
use apps\marriage\core\model\PlatformAccountBook;
use think\Exception;
use vm\com\BaseModel;
use vm\com\BaseService;

class PlatformAccountService extends BaseService
{

    /**
     * @return PlatformAccount
     */
    protected function getModel()
    {
        return new PlatformAccount();
    }

    /**
     * @return PlatformAccountBookService
     */
    private function getPlatformAccountBookService()
    {
        return service('PlatformAccountBook', SERVICE_NAMESPACE);
    }

    /**
     * 增加平台总收入
     * @param $money
     * @return bool|int|string|true
     */
    public function incMoney($money, $remark = '', $iidType = null, $iid = null, $extend = null)
    {
        return $this->getModel()->incAllMoney($money);
    }

    /**
     * 增加平台可用余额
     * @param $money
     * @return bool|int|string|true
     */
    public function incRemainingMoney($money, $remark = '', $iidType = null, $iid = null, $extend = null)
    {
        if($this->getModel()->incRemainingMoney($money)) {
            return $this->getPlatformAccountBookService()->record(PlatformAccountBook::TYPE_INCOME, $money, $iidType, $iid, $extend, $remark);
        }
        throw new Exception('操作失败');
    }

    /**
     * 扣减平台总收入
     * @param $money
     * @return bool|int|string|true
     */
    public function decRemainingMoney($money, $remark = '', $iidType = null, $iid = null, $extend = null)
    {
        if($this->getModel()->decRemainingMoney($money)) {
            return $this->getPlatformAccountBookService()->record(PlatformAccountBook::TYPE_EXPEND, $money, $iidType, $iid, $extend, $remark);
        }
        throw new Exception('操作失败');
    }
}